package com.zhangzhan.gulimallproduct.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangzhan.gulimallcommcon.util.CopyBean;
import com.zhangzhan.gulimallcommcon.util.PageUtils;
import com.zhangzhan.gulimallproduct.dao.AttrAttrgroupRelationDao;
import com.zhangzhan.gulimallproduct.entity.AttrAttrgroupRelationEntity;
import com.zhangzhan.gulimallproduct.service.AttrAttrgroupRelationService;
import com.zhangzhan.gulimallcommcon.util.Query;
import com.zhangzhan.gulimallproduct.vos.AttrAttrGroupRelationVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    private Map<String, Object> params;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        this.params = params;
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void attrRelationDelete(List<AttrAttrGroupRelationVo> vos) {
        this.getBaseMapper().attrRelationDelete(vos);
    }

    @Transactional
    @Override
    public void saveBatch(List<AttrAttrGroupRelationVo> vos) {
        List<AttrAttrgroupRelationEntity> relationEntities = CopyBean.copyBeanList(vos, AttrAttrgroupRelationEntity.class);
        this.saveBatch(relationEntities);
    }

}